#ifndef ACTIONLISTVIEW_H
#define ACTIONLISTVIEW_H

#include <QAbstractItemView>
#include "ActionListPainter.h"

class QPushButton;
class ActionListController;

class ActionListView : public QAbstractItemView
{
   Q_OBJECT
public:
   explicit ActionListView( ActionListController & actionController,
                            ActionListPainter *painter, QWidget *parent = 0);
   ~ActionListView();

public:
   virtual QRect visualRect(const QModelIndex &index) const;
   virtual void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible);
   virtual QModelIndex indexAt(const QPoint &point) const;

   void setActionBar(QWidget *actionBar);


public slots:
   void shiftFocusedUp();
   void shiftFocusedDown();
   void invalidateGeometries();
   void resetStyle();
   void displayError( const QString &);

protected:  // pure virtual functions implementation
   virtual QModelIndex moveCursor(CursorAction cursorAction,
                                  Qt::KeyboardModifiers modifiers);

   virtual int horizontalOffset() const;
   virtual int verticalOffset() const;

   virtual bool isIndexHidden(const QModelIndex &index) const;

   virtual void setSelection(const QRect &rect,
                             QItemSelectionModel::SelectionFlags command);
   virtual QRegion visualRegionForSelection(const QItemSelection &selection) const;

   void scrollContentsBy(int dx, int dy);

protected:
   void paintEvent(QPaintEvent *e);
   void keyPressEvent ( QKeyEvent * event );

protected slots:
   void updateGeometries();
   void onDoubleClickEvent( QModelIndex idx );
   void onShifted(int newPosition);
   void deleteActiveItem();

private:
   void paintListItem(int position );
   bool isCurrentIndexValid( const QModelIndex &index );
   QRect visualRectFromRow( int row ) const;
   QString format_display_text( const QStringList &display_data );
   QModelIndexList pickSelectedItems( const QRect &selection_rect );
   void markSelectedItems( QModelIndexList *selected_items,
                             QItemSelectionModel::SelectionFlags command);
   void setControllerGeometry(const QRect &activeItemArea);
   bool confirmToDelete();

   /* semi-constants reconfigurable by children */
protected:
   int m_itemHeight;
   int m_controllerHeigth;

private:
   ActionListPainter *m_painter;
   QWidget *m_actionBar;
   ActionListController & m_actionController;

private:
   int rowAt(int yViewport, int verticalScroll) const;
   void deleteSelection();
};

#endif // ACTIONLISTVIEW_H
